package de.bwv.javaproject.FunnyTokens.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import javax.swing.ImageIcon;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;

import de.bwv.javaproject.FunnyTokens.utils.ProgramUtils;
import de.java.swing.extension.ui.ExtendedFrame;
import de.java.swing.extension.ui.ExtendedImage;
import de.java.swing.extension.ui.ExtendedPanel;

/**
 * Fenster zur Auswahl des Spiels, das gespielt werden soll.
 * 
 * @author Patrick Haas
 * @date 28.01.2010
 * 
 * @version 1.0.0
 * 
 */
public class ChooseGameFrame extends ExtendedFrame implements ProgramUtils {

	// private static Logger LOG =
	// LoggerFactory.createLogger(ChooseGameFrame.class);

	private PropertyChangeSupport supportCloseWindow = new PropertyChangeSupport(this);

	public ChooseGameFrame(String title) {
		super(title);
		setLookAndFeel();
		initialize();
	}

	@Override
	public void doNothingOnClose() {
		supportCloseWindow.firePropertyChange(TITLE_CLOSE_PROGRAM, null, null);
	}

	private void initialize() {
		this.setSize(500, 250);
		int x = getComponent().getToolkit().getScreenSize().width / 2 - this.getSize().width / 2;
		int y = getComponent().getToolkit().getScreenSize().height / 2 - this.getSize().height / 2;

		this.setLocation(x, y);
		this.setResizable(false);

		this.setTitleFontColor(new Color(60, 90, 17));
		this.setSubtitle("Willkommen bei FunnyTokens, der lustigen Spielesammlung.");
		this.setSubtitleFontColor(new Color(60, 90, 17));
		this.rootPane.setBackgroundImage(new ExtendedImage("images\\welcomeframe\\ChooseGameBackground.png"));
		this.rootPane.setBackgroundImageAlignment(ExtendedPanel.BACKGROUND_IMAGE_ALIGNMENT_VERTICAL_STRETCHED);
		this.setLayout(new BorderLayout());
		this.setDecorationColor(new Color(60, 90, 17));
		this.setDecorationThickness(1);
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

		this.setDialogMenu(true);

		this.setCloseIcon(new ImageIcon("images\\welcomeframe\\close.png"));
		this.setStateMinimizeIcon(new ImageIcon("images\\welcomeframe\\minimize.png"));
	}

	private void setLookAndFeel() {
		// try {
		// UIManager.setLookAndFeel(TinyLookAndFeel.class.getName());
		// } catch (Exception e) {
		// LOG.warn("TinyLookAndFeel konnte nicht geladen werden.", e);
		// }

		// Standard Schriftart anpassen
		Font defaultFont = new Font("Arial", Font.BOLD, 12);
		UIManager.put("Label.font", defaultFont);
		UIManager.put("Table.font", defaultFont);

		// Tooltipfarbe anpassen
		UIManager.put("ToolTip.background", new ColorUIResource(Color.BLACK));
		UIManager.put("ToolTip.border", new ColorUIResource(Color.BLACK));
		UIManager.put("ToolTip.foreground", new ColorUIResource(Color.WHITE));

		// Scrollbalken anpassen
		UIManager.put("ScrollBar.thumb", new ColorUIResource(new Color(61, 34, 7)));
		UIManager.put("ScrollBar.thumbDarkShadow", new ColorUIResource(new Color(61, 34, 7)));
		UIManager.put("ScrollBar.thumbLightShadow", new ColorUIResource(new Color(61, 34, 7)));
		UIManager.put("ScrollBar.thumbHighlight", new ColorUIResource(new Color(61, 34, 7)));
		UIManager.put("ScrollBar.thumbShadow", new ColorUIResource(new Color(61, 34, 7)));
		UIManager.put("ScrollBar.track", new ColorUIResource(new Color(61, 34, 7)));
		UIManager.put("ScrollBar.trackHighlight", new ColorUIResource(new Color(61, 34, 7)));
		UIManager.put("ScrollBar.background", new ColorUIResource(new Color(61, 34, 7)));
		UIManager.put("ScrollBar.darkShadow", new ColorUIResource(new Color(61, 34, 7)));
		UIManager.put("ScrollBar.foreground", new ColorUIResource(new Color(61, 34, 7)));
		UIManager.put("ScrollBar.highlight", new ColorUIResource(new Color(61, 34, 7)));
		UIManager.put("ScrollBar.shadow", new ColorUIResource(new Color(61, 34, 7)));

		// Table
		UIManager.put("Table.gridColor", new ColorUIResource(new Color(61, 34, 7)));

	}

	/**
	 * @param listener
	 * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
	 */
	public void addWindowCloseListener(PropertyChangeListener listener) {
		supportCloseWindow.addPropertyChangeListener(listener);
	}

	/**
	 * @param listener
	 * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener)
	 */
	public void removeWindowCloseListener(PropertyChangeListener listener) {
		supportCloseWindow.removePropertyChangeListener(listener);
	}
}
